package com.yiyuan.weixin.weixinInservice;

/**
 * Created by admin on 2017/3/23.
 */

import com.yiyuan.weixin.Common.GlobalConstant;
import com.yiyuan.weixin.model.ReceiveXmlEntity;
import com.yiyuan.weixin.weixinInservice.Iml.WXResponsetText;
import com.yiyuan.weixin.weixinInservice.Iml.WXResposeNews;
import com.yiyuan.weixin.weixinInservice.service.WXResponseService;
import com.yiyuan.weixin.weixinOutservice.dao.ActionEventClick;

import javax.servlet.http.HttpServletResponse;

/*******
 * 微信事件分发
 */
public class WXEventDispatcherUtil {

    public static void eventDispatcher(HttpServletResponse resp, ReceiveXmlEntity xmlEntity) {
        WXResponseService wxRespondService=null;
        switch (xmlEntity.getEvent())
        {
            case GlobalConstant.Event_subscribe:

                wxRespondService=new WXResposeNews();
                break;
            case GlobalConstant.Event_unsubscribe :
                xmlEntity.setContent("取消订阅");
                wxRespondService=new WXResponsetText();
                break;
            case GlobalConstant.Event_SCAB:
                xmlEntity.setContent("当前事件"+xmlEntity.getEvent());
                wxRespondService=new WXResponsetText();
                break;
            case GlobalConstant.Event_LOCATION :
                if (GlobalConstant.LOCATION_CHENK)
                {
                    xmlEntity.setContent("当前位置"+xmlEntity.getLatitude()+","+xmlEntity.getLongitude());
                    wxRespondService=new WXResponsetText();
                }

                break;
            case GlobalConstant.Event_CLICK :
                String content=ActionEventClick.actionDispatch(xmlEntity.getEventKey());
                if (content==null)
                    content="当前事件"+xmlEntity.getEvent()+",key"+xmlEntity.getEventKey();
                xmlEntity.setContent(content);
                wxRespondService=new WXResponsetText();
                break;
            case GlobalConstant.Event_VIEW :
                xmlEntity.setContent("当前事件"+xmlEntity.getEvent());
                wxRespondService=new WXResponsetText();
                break;
            default:
        }
        if (wxRespondService!=null)
            wxRespondService.wxRespond(resp,xmlEntity);
    }
}
